package com.wjs.spring.homework;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class StudentProxy implements InvocationHandler {
    private Student student;

    public StudentProxy(Student student) {
        this.student = student;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        MyAspect myAspect = new MyAspect();
        Object invoke = method.invoke(student, args);
        if(method.getName().equals("study")){
            myAspect.prepareClazz();
            method.invoke(student, args);
            myAspect.startClazz();
            myAspect.endClazz();
        }else{
            myAspect.prepareDoHomeWork();
            method.invoke(student, args);
            myAspect.startDoHomeWork();
            myAspect.finishHomeWork();
        }
        return invoke;
    }
}
